package com.fs.groupSeven.service.impl;

import com.fs.groupSeven.Dao.ClassroomDao;
import com.fs.groupSeven.pojo.Classroom;
import com.fs.groupSeven.service.ClassroomService;
import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

/**
 * @description:
 * @author: fbb
 * @createDate: 2020/9/29 20:19
 */

@Service
public class ClassroomServiceImpl implements ClassroomService {
    private ClassroomDao classroomDao;

    @Autowired
    public ClassroomServiceImpl(ClassroomDao classroomDao) {
        this.classroomDao = classroomDao;
    }

    @Override
    public List<Classroom> getClassroomList() {
        List<Classroom> classrooms = classroomDao.queryClassroomList();
        return classrooms;
    }

    @Override
    public Classroom getOneByClassroomId(Integer classroomId) {
        Classroom classroom = classroomDao.queryById(classroomId);
        return classroom;
    }

    @Override
    public boolean updateByClassroom(Classroom classroom) {
        int insult = classroomDao.updateByClassroom(classroom);
        return insult > 0;
    }

    @Override
    //@Transactional //注明当前方法事务性执行
    public List<Classroom> getClassroomMessageLike(String roomMessage) {
        List<Classroom> classrooms = classroomDao.queryByRoomMessage(roomMessage);
        return classrooms;
    }

    @Override
    public PageInfo<Classroom> getClassroomsByPage(Integer currentPage, Integer pageSize) {
        Page<Object> objects = PageHelper.startPage(currentPage, pageSize);
        List<Classroom> classrooms = classroomDao.queryClassroomList();
        PageInfo<Classroom> classroomPageInfo = new PageInfo<>(classrooms);
        return classroomPageInfo;
    }

    @Override
    public boolean addOneRoom(Classroom classroom) {
        int insult = classroomDao.addOneRoom(classroom);
        return insult > 0;
    }
}
